package controller

import (
	"time"

	"github.com/dgrijalva/jwt-go"
	"github.com/gin-gonic/gin"

	myjwt "project/study-go/http/base/jwt"
)

type TestController struct{}

func (t *TestController) RegisterRoute(g *gin.RouterGroup) {
	test := g.Group("/test")
	test.Any("/t1", t1)
}

func t1(c *gin.Context) {
	claims := &myjwt.UserClaims{
		nil,
		jwt.StandardClaims{
			Audience:  "hahaha",
			ExpiresAt: time.Now().Add(3600 * time.Second).Unix(),
			Id:        "sds",
			IssuedAt:  time.Now().Unix(),
			Issuer:    "zch",
			NotBefore: time.Now().Unix(),
			Subject:   "hehehe",
		},
	}
	token, err := myjwt.JwtMan.Generate(claims)
	if err != nil {
		c.JSON(500, nil)
		c.Abort()
		return
	}
	c.JSON(200, gin.H{
		"msg": token,
	})
}
